<?php

namespace console\controllers;

use Yii;
use yii\db\ActiveRecord;
use yii\console\Controller;
use yii\db\Query;


class NightController extends Controller {
    public function init()
    {        
        Yii::$app->getUrlManager()->setBaseUrl('/mkt/backend/web/index.php');
        Yii::$app->getUrlManager()->setHostInfo('http://juyong8.com');
        Yii::$app->getUrlManager()->setScriptUrl('/mkt/backend/web/index.php');
        Yii::$app->wx->setGhId(MGh::GH_XIANGYANGUNICOM);
    }
    
    public function actionIndex() {
        set_time_limit(0);
        if (!ini_set('memory_limit', '-1'))
            yii::info("ini_set(memory_limit) error");
        $time = microtime(true);
        $yesterday = date("Y-m-d", strtotime("-1 day"));

        $theFirstDayOfLastMonth = U::getFirstDayOfLastMonth();
        $theLastDayOfLastMonth = U::getLastDayOfLastMonth();

        yii::info("###########" . __CLASS__ . " BEGIN");

        //self::confirmSceneDetail();

        if (date('N') == 1) {
            yii::info("Begin Weekly ...");
            yii::info("End Weekly ...");
        }

        if (date('j') == 1) {
            yii::info("Begin Monthly ...");

            $tableName = MOrder::tableName();
            Yii::$app->db->createCommand("OPTIMIZE TABLE $tableName")->execute();
            yii::info("OPTIMIZE TABLE $tableName");

            yii::info("End Monthly ...");
        }

        if (date('j') == 1) {
        {
//         yii::info("on 1st every month, add recommending fans fee of last month for user ...");
            $start_date = '2015-04-01';
            $end_date = date("Y-m-d", strtotime("-1 month"));
            yii::info("NightController::addRecommendFanAmount runs [".$start_date.", ".$end_date.']');
        }

        self::checkSmBalance();

        yii::info("###########" . __CLASS__ . " END, (time: " . sprintf('%.3f', microtime(true) - $time) . "s)");
    }

}


